﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Dto生成器.UI
{
    public partial class Login : Form
    {
        private string connString;
        public Login()
        {
            InitializeComponent();
            this.textBox1.Text = ConfigurationManager.AppSettings["DateBaseService"];
            this.textBox2.Text = ConfigurationManager.AppSettings["DateBase"];
            this.textBox3.Text = ConfigurationManager.AppSettings["UserName"];
            this.textBox4.Text = ConfigurationManager.AppSettings["PassWord"];
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string db = this.textBox1.Text.ToString();
            string dataBase = this.textBox2.Text;
            string userName = this.textBox3.Text.ToString();
            string passWord = this.textBox4.Text.ToString();
            try
            {
                if (DataVerification(db, userName, passWord, dataBase))
                {
                    this.connString = string.Format("Data Source={0};Initial Catalog={1};Integrated Security=false;User={2};Password={3};", new object[]
                        {
                       db,
                       dataBase,
                       userName,
                       passWord
                        });
                    SqlConnection expr_B1 = new SqlConnection(this.connString);
                    expr_B1.Open();
                    expr_B1.Close();
                    base.Close();
                }
            }
            catch (Exception ex)
            {

            }
        }


        #region 登陆数据验证
        private bool DataVerification(string db, string userName, string passWord, string dataBase)
        {
            if (string.IsNullOrEmpty(db))
            {
                MessageBox.Show("请输入数据库地址");
                return false;
            }
            if (string.IsNullOrEmpty(userName))
            {
                MessageBox.Show("请输入数据库账号");
                return false;
            }
            if (string.IsNullOrEmpty(passWord))
            {
                MessageBox.Show("请输入数据库密码");
                return false;
            }
            if (string.IsNullOrEmpty(dataBase))
            {
                MessageBox.Show("请输入需要连接的数据库");
                return false;
            }
            return true;
        }
        #endregion

       

    }
}
